import math
def is_prime(a):
    if a <= 1:
        return False
    if a == 2:
        return True
    if a > 2 and a % 2 == 0:
        return False
    max_n = math.floor(math.sqrt(a))
    for d in range(3, 1 + max_n, 2):
        if a % d == 0:
            return False
    return True

def find_closest_prime(input_str):
    words_to_num = {"zero": "0", "one": "1", "two": "2", "three": "3", "four": "4", "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"}
    b = input_str.split()
    if len(b) != 3:
        print("Wrong input")
        exit()
    for i in b:
        if i not in words_to_num:
            print("Wrong input")
            exit()

    b = [words_to_num[c] for c in b]
    c = int(''.join(b))
    if 100 <= c <= 999:
        i = 0
        while True:
            if is_prime(c - i) or is_prime(c + i):
                if is_prime(c - i) and is_prime(c + i):
                    print(f"{c - i} {c + i}")
                elif is_prime(c - i):
                    print(c - i)
                else:
                    print(c + i)
                break
            i += 1
    else:
        print("Wrong input")

input_str = input()
find_closest_prime(input_str)